package com.cskaoyan.javase.oop1._9exercise;

/**
 * 读程序题,先找main方法,main方法是程序的入口方法
 * 启动main方法 触发类加载
 *
 * 程序的输出是:
 * Cat price  该句是Student类的成员变量的显式赋值,所输出的语句
 * Student age 该句是Student类的this单参构造器所输出的语句
 * Student age,name 该句是Student类的双参new对象的构造器 所输出的语句
 *
 * @since 11:25
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class Demo {
    public static void main(String[] args) {
        Student s = new Student(18, "长风");
        System.out.println(s.age);
        System.out.println(s.name);
        System.out.println(s.var);
        System.out.println(s.cat.price);
    }
}

class Student {
    int age = 10;
    String name = "张三";
    double var = 20;

    public Student(int age) {
        System.out.println("Student age");
        this.age = age;
    }

    public Student() {
    }

    public Student(int age, String name) {
        this(age);
        System.out.println("Student age,name");
        this.name = name;
    }

    /*
        引用数据类型成员变量的显式赋值
        这里需要创建Cat对象
        首先需要类加载Cat
        接下来创建Cat对象
     */
    Cat cat = new Cat(1000);
    Cat c2;
    // 成员变量的显式赋值中创建自身对象
    // Student s = new Student();
}

class Cat {
    double price;

    public Cat() {
    }

    public Cat(double price) {
        System.out.println("Cat price");
        this.price = price;
    }
}